export const publicVM = {
    data() {
        return {

        }
    },
    methods: {
        //排序峰谷时
        sortType(val) {
            let tmp = val.toString()
            return tmp.split(',').sort()
        },
        tableExport(fileurls) {
            if (fileurls == "" || typeof fileurls == "unedfined") {
                return;
            }

            var downiframe = document.querySelector("#downiframe");
            if (downiframe) {
                downiframe.parentNode.removeChild(downiframe);
            }
            try {
                var elemIF = document.createElement("iframe");
                elemIF.id = "downiframe";
                elemIF.src = fileurls;
                elemIF.style.display = "none";
                document.body.appendChild(elemIF);
            } catch (e) {
                console.dir("error");
            }
        },
        // checkNumber(num) { //正正数或有两位小数
        //     if (!/^\d{1,6}(\.\d{1,2})?$/.test(num)) {
        //         return false;
        //     } else {
        //         return true;
        //     }
        // },
        checkTimes(num) { //两位正整数
            return /^[1-9]\d*$/g.test(num)
        },
        /**
         * e Dom对象
         * w 位数
         * ws 小数位数
         * min 最小值
         * el 当前值名
         */
        checkNumer(e, w, ws, min, el) {
            let val = Number($(e.target).val())
            if (val < Math.pow(10, w) && val > 0) {
                if (ws) {
                    $(e.target).val(val.toFixed(ws))
                    this[el] = val.toFixed(ws)
                } else {
                    $(e.target).val(Math.ceil(val))
                    this[el] = Math.ceil(val)
                }
            } else {
                $(e.target).val(min)
                this[el] = min
                this.$message({
                    message: `请输入1~${w}位正${ws == 0?'整':''}数`,
                    type: 'warning'
                });
            }
        },
        getUserType(data) {
            let arr = [1, 2, 4]
            let result = []
            if (!data) {
                for (let i = 0; i < arr.length; i++) {
                    if (arr.includes(data)) {
                        result.push(data)
                        break;
                    }
                    for (let j = 0; j < arr.length; j++) {
                        let a = data - arr[i];
                        if (a > 0) {
                            if ((a - arr[j]) == 0) {
                                if (!result.includes(arr[i])) {
                                    result.push(arr[i])
                                }
                            }
                        }
                    }

                }
                return arr
            } else {
                return result.length > 0 ? result : arr
            }
        },
        //中文
        checkCh(ch){
            return /^[^\u4e00-\u9fa5]+$/.test(ch);
        },
        //含有小数
        checkNum(num){
            return /^\d+(\.\d+)?$/.test(num);
        },
        //数字
        checkNum1(n){
            return /^[0-9]*$/.test(n);
        },
    }
}